﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:AEA.WPFControls">

    <Style TargetType="{x:Type local:SplitButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:SplitButton}">
                    <Grid x:Name="LayoutRoot">
                        <ComboBox x:Name="PART_ComboBox"
                                  IsSynchronizedWithCurrentItem="True" />
                        <Button x:Name="PART_Button"
                                Margin="0,0,16,0">
                            <Grid Width="{Binding Path=ActualWidth, ElementName=PART_Button, Mode=Default}"
                                  Height="{Binding Path=ActualHeight, ElementName=PART_Button, Mode=Default}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="0.507*" />
                                    <RowDefinition Height="0.493*" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="0.551*" />
                                    <ColumnDefinition Width="0.551*" />
                                    <ColumnDefinition Width="0.229*" />
                                </Grid.ColumnDefinitions>
                                <Image x:Name="PART_Image"
                                       Grid.RowSpan="2"
                                       HorizontalAlignment="Center"
                                       VerticalAlignment="Center"
                                       Visibility="Collapsed" />
                                <ContentPresenter x:Name="PART_Content"
                                                  HorizontalAlignment="Center"
                                                  Grid.RowSpan="2"
                                                  Content="Button"
                                                  VerticalAlignment="Center"
                                                  Grid.ColumnSpan="3" />
                            </Grid>
                        </Button>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSourceEmpty"
                                           Value="False" />
                                <Condition Property="TextImageRelation"
                                           Value="ImageBeforeText" />
                                <Condition Property="DisplayStyle"
                                           Value="TextAndImage" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Visibility"
                                    TargetName="PART_Image"
                                    Value="Visible" />
                            <Setter Property="Grid.ColumnSpan"
                                    TargetName="PART_Content"
                                    Value="2" />
                            <Setter Property="Grid.Column"
                                    TargetName="PART_Content"
                                    Value="1" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSourceEmpty"
                                           Value="False" />
                                <Condition Property="TextImageRelation"
                                           Value="TextBeforeImage" />
                                <Condition Property="DisplayStyle"
                                           Value="TextAndImage" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Grid.Column"
                                    TargetName="PART_Content"
                                    Value="0" />
                            <Setter Property="Grid.ColumnSpan"
                                    TargetName="PART_Content"
                                    Value="1" />
                            <Setter Property="Visibility"
                                    TargetName="PART_Image"
                                    Value="Visible" />
                            <Setter Property="Grid.Column"
                                    TargetName="PART_Image"
                                    Value="1" />
                            <Setter Property="Grid.ColumnSpan"
                                    TargetName="PART_Image"
                                    Value="2" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSourceEmpty"
                                           Value="False" />
                                <Condition Property="TextImageRelation"
                                           Value="ImageAboveText" />
                                <Condition Property="DisplayStyle"
                                           Value="TextAndImage" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Grid.Column"
                                    TargetName="PART_Content"
                                    Value="1" />
                            <Setter Property="Grid.ColumnSpan"
                                    TargetName="PART_Content"
                                    Value="1" />
                            <Setter Property="Grid.Row"
                                    TargetName="PART_Content"
                                    Value="1" />
                            <Setter Property="Grid.RowSpan"
                                    TargetName="PART_Content"
                                    Value="1" />
                            <Setter Property="Visibility"
                                    TargetName="PART_Image"
                                    Value="Visible" />
                            <Setter Property="Grid.Column"
                                    TargetName="PART_Image"
                                    Value="1" />
                            <Setter Property="Grid.ColumnSpan"
                                    TargetName="PART_Image"
                                    Value="1" />
                            <Setter Property="Grid.Row"
                                    TargetName="PART_Image"
                                    Value="0" />
                            <Setter Property="Grid.RowSpan"
                                    TargetName="PART_Image"
                                    Value="1" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSourceEmpty"
                                           Value="False" />
                                <Condition Property="TextImageRelation"
                                           Value="TextAboveImage" />
                                <Condition Property="DisplayStyle"
                                           Value="TextAndImage" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Grid.Column"
                                    TargetName="PART_Content"
                                    Value="1" />
                            <Setter Property="Grid.ColumnSpan"
                                    TargetName="PART_Content"
                                    Value="1" />
                            <Setter Property="Grid.Row"
                                    TargetName="PART_Content"
                                    Value="0" />
                            <Setter Property="Grid.RowSpan"
                                    TargetName="PART_Content"
                                    Value="1" />
                            <Setter Property="Visibility"
                                    TargetName="PART_Image"
                                    Value="Visible" />
                            <Setter Property="Grid.Column"
                                    TargetName="PART_Image"
                                    Value="1" />
                            <Setter Property="Grid.ColumnSpan"
                                    TargetName="PART_Image"
                                    Value="1" />
                            <Setter Property="Grid.Row"
                                    TargetName="PART_Image"
                                    Value="1" />
                            <Setter Property="Grid.RowSpan"
                                    TargetName="PART_Image"
                                    Value="1" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="DisplayStyle"
                                           Value="Image" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Visibility"
                                    TargetName="PART_Image"
                                    Value="Visible" />
                            <Setter Property="Visibility"
                                    TargetName="PART_Content"
                                    Value="Collapsed" />
                            <Setter Property="Grid.Column"
                                    TargetName="PART_Image"
                                    Value="0" />
                            <Setter Property="Grid.ColumnSpan"
                                    TargetName="PART_Image"
                                    Value="2" />
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>